﻿using System;
using System.Data;
using System.Web;
using System.Data.SqlClient;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.news.show
{
    public partial class re_news : ModulePage
    {

        private void OO0O0O11()
        {
            int newsId = Convert.ToInt32(this.ViewState["NewsId"].ToString());
            DataTable table = new NewsCommentDao().SelectByNewsId(base.Conn, newsId);
            if (table.Rows.Count == 0)
            {
                this.litNewsComment.Text = base.ShowMessage("暂无评论");
            }
            else
            {
                this.litNewsComment.Text = "";
                this.rptNewsComment.DataSource = table;
                this.rptNewsComment.DataBind();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int newsId = (Request.QueryString["news_id"] == null) ? 0 : int.Parse(Request.QueryString["news_id"].ToString());
                this.ViewState["NewsId"] = newsId;
                DataTable table = new NewsDao().SelectByNewsId(base.Conn, newsId, base.User.Identity.Name);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无新闻记录");
                    return;
                }
                new ConfigManager();
                UserCache cache = new UserCache();
                bool flag = false;
                if ((!flag && (table.Rows[0]["ToId"] != DBNull.Value)) && (table.Rows[0]["ToId"].ToString() == "ALL_DEPT"))
                {
                    flag = true;
                }
                if ((!flag && (table.Rows[0]["ToId"] != DBNull.Value)) && (string.Format(",{0},", table.Rows[0]["ToId"].ToString()).IndexOf(string.Format(",{0},", cache.DeptId.ToString())) >= 0))
                {
                    flag = true;
                }
                if ((!flag && (table.Rows[0]["ToPriv"] != DBNull.Value)) && (string.Format(",{0},", table.Rows[0]["ToPriv"].ToString()).IndexOf(string.Format(",{0},", cache.PrivId.ToString())) >= 0))
                {
                    flag = true;
                }
                if ((!flag && (table.Rows[0]["ToUser"] != DBNull.Value)) && (string.Format(",{0},", table.Rows[0]["ToUser"].ToString()).IndexOf(string.Format(",{0},", base.User.Identity.Name)) >= 0))
                {
                    flag = true;
                }
                if (!flag)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPromptClose("无权限查看");
                    return;
                }
                this.litSubject.Text = table.Rows[0]["Subject"].ToString();
                this.OO0O0O11();
            }
            if (this.Page.IsPostBack)
            {
                NewsCommentData data = new NewsCommentData();
                NewsCommentDao dao2 = new NewsCommentDao();
                data.NewsId = Convert.ToInt32(this.ViewState["NewsId"].ToString());
                data.UserId = base.User.Identity.Name;
                data.Content = this.txtContent.Value;
                data.ReplyTime = DateTime.Now;
                dao2.Insert(base.Conn, data);
                this.txtContent.Value = "";
                this.OO0O0O11();
            }
        }

 

    }
}
